#ifndef SETTINGS_H
#define SETTINGS_H

#define DEFAULT_WINDOW_NAME "Settings"
#define DEFAULT_WINDOW_WIDTH    350
#define DEFAULT_WINDOW_HEIGHT   400
#define DEFAULT_WINDOW_POS_X    0
#define DEFAULT_WINDOW_POS_Y    0
#define DEFAULT_MIN_UPDATE_TIME 3
#define DEFAULT_MAX_UPDATE_TIME 60


#include <QDialog>
#include <QLabel>
#include <QLineEdit>
#include <QSettings>
#include <QColor>
#include <QIcon>
#include <QSpinBox>
#include <QCheckBox>

class Settings : public QDialog
{
    Q_OBJECT
public:
    Settings(QWidget *parent = 0);
    ~Settings();

    QSize getWindowSize();
    QPoint getWindowPosition();
    QByteArray getToolBarState();
    void updateWindowSize(int w, int h);
    void updateWindowPosition(int x, int y);
    void updateToolBarState(const QByteArray &state);

    QString getUsername();
    QString getPassword();
    void loginCallBack(bool isError);
    int getUpdateTime();

    QString getStatusOwnerColor();
    QString getUsersColor();
    QString getLinksColor();
    bool getIsStatusOwnerBold();
    bool getIsUsersBold();
    bool getIsLinksBold();

    QString getCacheDir();

signals:
    void settingsChanged();
    void newLoginInfo();

private:
    QSettings *settings;
    QLabel *informationAreaL;
    void informationArea(QString text, bool isError = false);
    QPushButton *saveSettingsBtn;

    QPoint windowPosition;
    QSize windowSize;
    QByteArray toolBarState;

    QString cacheDir;

    //Main
    QLineEdit *username;
    QString __username;
    QLineEdit *password;
    QString __password;
    QSpinBox *updateTime;

    //Style
    QPushButton *statusOwnerColorBtn;
    QPushButton *usersColorBtn;
    QPushButton *linksColorBtn;
    QColor statusOwnerColor;
    QColor usersColor;
    QColor linksColor;
    QCheckBox *statusOwnerBold;
    QCheckBox *usersBold;
    QCheckBox *linksBold;

    QIcon createIconForBtn(const QColor &color);


    void loadSettings();
    void saveSettings();
    bool isLoginInfoExist();

private slots:
    void saveSettingsClicked();

    void changeStatusOwnerColor();
    void changeUsersColor();
    void changeLinksColor();
protected:
    void closeEvent(QCloseEvent *event);

};

#endif // SETTINGS_H
